<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../js/httpRequest.js"></script>
<script language="JavaScript">
	function del(){
		if(confirm("삭제 하시겠습니까?")==false)return;
		f.action = "BoardDelete.do";
		f.submit();
	}
	
	
	function modify(){
		f.action = "BoardModifyForm.do";
		f.submit();
	}
	
	
	
	function reply(){

        document.f.action = "BoardReplyForm.do";

        document.f.submit();

    }
	
	function reply_view(no){
		var dv_frame = document.getElementById("reply_frame");
		/* if(dv_frame.style.display=="none"){
			dv_frame.style.display="block";
			sendRequest("../ajax/get_reply.jsp", "b_no="+no, resultReply, "POST");
		}else if(dv_frame.style.display=="block"){
			dv_frame.style.display="none";
		} */
		sendRequest("../ajax/get_reply.jsp", "b_no="+no, resultReply, "POST");
	}
	function resultReply(){
		if(xhr.readyState==4 && xhr.status==200){
			//del_reply_v();
			//del_reply_w();
			var res_list=xhr.responseText;
			alert(res_list);
			var dv_1 = document.getElementById("reply_v");
			var tb_1 = document.createElement("tb");
			
			if(res_list.length > 0){
				for(var i=0; i<res_list.length; i++){
					var tr_1 = document.createElement("tr");
					var tr_2 = document.createElement("tr");
					var td = document.createElement("td");
					var td_1 = document.createElement("td");
					var td_2 = document.createElement("td");
					td_2.setAttribute("colspan","2");
					var a_1 = document.createElement("a");
					a_1.setAttribute("href", "#");
					a_1.setAttribute("onclick", "reply_modify("+res_list[i].b_no+")");
					a_1.innerHTML="수정&nbsp;|&nbsp;";
					var a_2 = document.createElement("a");
					a_2.setAttribute("href", "#");
					a_2.setAttribute("onclick", "reply_delete("+res_list[i].b_no+")");
					a_2.innerHTML="삭제";
					
					td.innerHTML=res_list[i].b_writer+"&nbsp;|&nbsp;";
					td_1.innerHTML=res_list[i].b_writedate+"&nbsp;|&nbsp;";
					td_1.appendChild(a_1);
					td_1.appendChild(a_2);
					
					td_2.innerHTML=res_list[i].b_content;
					
					tr_1.appendChild(td);
					tr_1.appendChild(td_1);
					tr_2.appendChild(td_2);
					
					tb_1.appendChild(tr_1);
					tb_1.appendChild(tr_2);
					dv_1.appendChild(tb_1);
					
				}
			}
			var dv_2 = document.getElementById("reply_w");
			var tb_2 = document.createElement("tb");
			var tr_3 = document.createElement("tr");
			var td_3 = document.createElement("tr");
			var td_4 = document.createElement("tr");
			
			var text_a = document.createElement("TEXTAREA");
			
			text_a.setAttribute("rows", "5");
			text_a.setAttribute("cols", "50");
			text_a.setAttribute("id", "b_content");
			
			var input_bt=document.createElement("input");
			var param_1 = ${cvo.b_no};
			input_bt.setAttribute("type", "button");
			input_bt.setAttribute("value", "댓글입력");
			input_bt.setAttribute("onclick", "reply_write("+param_1+")");
			
			td_3.appendChild(text_a);
			td_4.appendChild(input_bt);
			
			
			tr_3.appendChild(td_3);
			tr_3.appendChild(td_4);
			
			tb_2.appendChild(tr_3);
			dv_2.appendChild(tb_2);
			
		}
	}
	function del_reply_v(){
		var dv_1 = document.getElementById("reply_v");
		var cnt_1 = dv_1.childNodes.length;
		for(var i=0; i<cnt_1; i++){
			dv_1.removeChild(dv_1.childNodes[0]);
		}
	}
	function del_reply_w(){
		var dv_2 = document.getElementById("reply_w");
		var cnt_2 = dv_2.childNodes.length;
		
		for(var i=0; i<cnt_2; i++){
			dv_2.removeChild(dv_2.childNodes[0]);
		}
	}
	
	/* function reply_write(b_no){
		var content=document.getElementById("b_content").value;
		//alert("b_no:"+b_no+"/b_content:"+content);
		var menu_no=${cvo.menu_no};
		var cate_no=${cvo.cate_no};
		var title_no=${cvo.title_no};
		var param="b_no="+b_no+"&b_content="+encodeURIComponent(content)+
				   "&menu_no="+menu_no+"&cate_no="+cate_no+"&title_no="+title_no;
		sendRequest("../ajax/set_reply.jsp", param, resultReply, "POST");
	} */
	
</script>

</head>
<body>

<div>
	<form name="f" method="post">
		
		<input type="hidden" name="b_no" value="${cvo.b_no }">
		<input type="hidden" name="b_subject" value="${cvo.b_subject }">
		<input type="hidden" name="b_writer" value="${cvo.b_writer }">
		<input type="hidden" name="b_filename" value="${cvo.b_filename }">
		<input type="hidden" name="b_content" value="${cvo.b_content }">
		<%-- <input type="hidden" name="page" value=${param.page }> --%>
		<table width="700" border="2px" bordercolor="white" cellspacing="0" cellpadding="0">
			<tr>
				<td class="td_d_1" colspan="2">${cvo.b_subject }</td>
			</tr>
			<tr>
				<td class="td_d_2">${cvo.b_writer }</td>
				<td class="td_d_2">${cvo.b_writedate }</td>
			</tr>
		<c:if test="${cvo.b_filename!='no_file' }">	
			<tr>
				<td width="120" height="25" class="td_d_4">첨부파일</td>
				<td class="td_d_2">
					<a href="#" onclick="download('${cvo.b_filename}')">${cvo.b_filename }</a>
				</td>
			</tr>
		</c:if>
			<tr>
				<td colspan="2" class="td_d_3" width="700px" height="300px" style="word-wrap:break-word;word-break:break-all">
					<pre>${cvo.b_content }</pre>
				</td>
			</tr>
			<tr>
				<td colspan="2" height="25" class="td_d_4">
					<a href="#" onclick="reply_view('${cvo.b_no}')">댓글보기</a>
				</td>
			</tr>
			     	
		</table>
	</form>
</div>

<div id="reply_frame" >
	<div id="reply_v">
	
	</div>
	<div id="reply_w">
	
	</div>
</div>







<%-- 
<div id="reply_1" style="display:none;">
<table width="700" border="1px" bordercolor="yellow" cellspacing="0" cellpadding="0">
	<tr>
		<td height="5"></td>
	</tr>
<c:if test="${!empty reply_list }">	
<c:forEach var="re" items="${reply_list }">	
	<tr>
		<td>
			${re.b_content }
		</td>
	</tr>
</c:forEach>
</c:if>
</table>

<form>	
	<input type="hidden" name="b_no" value="${cvo.b_no }">
	<input type="hidden" name="menu_no" value="${cvo.menu_no }">
	<input type="hidden" name="cate_no" value="${cvo.cate_no }">
	<input type="hidden" name="title_no" value="${cvo.title_no }">
	<table>
		<tr>
			<td style="padding-left:30px">
				<textarea name="b_content" rows="5" cols="50"></textarea>
			</td>
			<td>
				<input type="button" value="덧글입력" onclick="reply_write(this.form,${cvo.b_no})">
			</td>
		</tr>	
		<tr>
			<td colspan="2" align="right"><img src="../img/btn_list.gif" onClick="javaScript:location.href='BoardList.do?page=${param.page}'" style="cursor:hand">
			<img src="../img/btn_reply.gif" onClick="reply()" style="cursor:hand">
	<c:if test="${id=='글쓴이일경우' }">		
			<img src="../img/btn_modify.gif" onClick="modify()" style="cursor:hand">
			
			<img src='../img/btn_delete.gif' onClick="del()" style='cursor:hand'>
	</c:if>
			</td>
		</tr>
	</table>
</form>
</div> --%>

</body>
</html>